<template>
  <div :DetailData="DetailData" :class="{'web':user.admin !=1}">
    <el-dialog   :title="fromTitle" :visible.sync="shows" :width="width" style="text-align: left"  >
      <el-form :model="from" :rules="rules" ref="from" label-width="125px" label-position="left" style="width:450px">
        <el-form-item label="费用名称:" v-show="costNameShow" >
          <el-input type="textarea"
                    autosize
                    placeholder="请输入内容"
                    v-model="from.costName">
          </el-input>
        </el-form-item>
        <el-form-item v-if="costNameShow" label="金额:" prop="cost">
          <el-input placeholder="请输入金额"  v-model="from.cost" class="input-with-select">
           <span slot="append">
              {{fromData.nuit}}
            </span>
          </el-input>
        </el-form-item>
        <el-form-item v-if="!costNameShow && ctnPrice" label="集装箱费用单价:" prop="ctnPrice">
          <el-input placeholder="请输入金额"  v-model="from.ctnPrice " class="input-with-select">
            <span slot="append">
              {{fromData.nuit}}
            </span>
          </el-input>
        </el-form-item>
        <el-form-item v-if="!costNameShow && linePrice" label="运输费用单价:" prop="linePrice">
          <el-input placeholder="请输入金额"  v-model="from.linePrice" class="input-with-select">
           <span slot="append">
              {{fromData.nuit}}
            </span>
          </el-input>
        </el-form-item>
        <el-form-item v-if="!costNameShow && from.consignPrice" label="拖车费用单价:" prop="consignPrice">
          <el-input placeholder="请输入金额"  v-model="from.consignPrice" class="input-with-select">
            <span slot="append">
              {{fromData.nuit}}
            </span>
          </el-input>
        </el-form-item>
        <div class="" style="margin-top: 40px;text-align: center">
          <el-button type="primary" size="medium"   style="width: 45%" @click="setFn()" >确 定</el-button>
          <el-button size="medium"  @click="shows = false;from.cost = '';from.costName = ''" style="width:45%" >取 消</el-button>
        </div>
      </el-form>
    </el-dialog>
    <p class="title clearfix" :us="us">
      <span class="left"> 订单费用 </span>
      <span class="right">
            <el-switch
              v-model="fromData.nuit"
              :width='width2'
              style="font-size: 12px;color: #999"
              active-value="$"
              inactive-value="￥"
              active-color="#333"
              active-text="$美元"
              inactive-text="￥人民币"
              inactive-color="#999" >
          </el-switch>
          <span  v-show="fromData.rate" style="font-size: 14px;color: #999;margin-left: 10px">
                今日汇率 $100 = ￥{{parseFloat((fromData.rate*100)).toFixed(2)}}
              </span>
          </span>

    </p>
    <div class="list  clearfix prec" :updateStatusData="updateStatusData" style=" position: relative;background-color:#f2f7fa;padding: 0px;" >
      <div class="cuntBox" style="">
        <div class="clearfix cuntCop" style="">
          <div class="textRight clearfix" v-show="fromData.ctnPrice && fromData.ctnPrice != 0.00" >
            <div class="right money"><p>{{ fromData.nuit}}  {{fromData.nuit=="￥"?fromData.ctnPrice:fromData.ctnPriceD}}</p> </div>
            <div class="right"><p>集装箱费 <span class="dotted"  >总价</span></p></div>
          </div>
          <div class="textRight clearfix"   >
            <div class="right money"><p>{{ fromData.nuit}} {{fromData.nuit=="￥"?fromData.linePrice:fromData.linePriceD}}</p></div>
            <div class="right"><p> 运&nbsp输&nbsp费 <span class="dotted">总价</span></p> </div>
          </div>
          <div class="textRight clearfix"   >
            <div class="right money"><p>{{ fromData.nuit}} {{ (fromData.nuit=="￥"?parseFloat(fromData.consignPrice)+ parseFloat(fromData.sendPrice): parseFloat(fromData.consignPriceD) + parseFloat(fromData.sendPriceD)).toFixed(2)}}</p> </div>
            <div class="right"><p>增值费用<span class="dotted">总价</span></p> </div>
          </div>
          <div class="textRight clearfix"  v-show="fromData.costTotal && fromData.costTotal != 0.00" >
            <div class="right money"><p>{{ fromData.nuit}} {{ fromData.nuit=="￥" ? fromData.costTotal:fromData.costTotalD}}</p> </div>
            <div class="right "><p>额外费用 <span class="dotted">总价</span></p> </div>
          </div>
          <div class="textRight clearfix" style=" margin-top: 10px"  >
            <div class="right money"><p class="cuntNubmer" > <span style="font-size:16px;margin-right: 2px">{{ fromData.nuit}} </span> {{ fromData.nuit=="￥"?fromData.cvalue:fromData.cvalueD}}</p> </div>
            <div class="right"><p class="cuntText">合计费用</p> </div>
          </div>
        </div>
      </div>
      <div class="left" style="width: 70%;min-height:155px;background-color: #fff">
        <p class="precTitle" > 费用</p>
        <div class="cop">
          <p class="clearfix" v-for="(list,index) in transitCost" style="text-align: left;position: relative">
            <!--铁路箱 20gp X 20 -->
            <span class="index">
                      {{index +1}}
                  </span>
            <span style="position: absolute;top: 5px;right: 0px;color: #0062a2;font-size: 12px" v-show="!fromData.rt">
                  {{ ' X ' + list.cartonCount}}
                </span>
            <span class="td"  v-show="list.cartonType" style="width: 80%">
                  {{list.ctnOwner }} {{list.cartonType }}
                </span>
            <span class="td"  v-show="fromData.TR" style="width: 80%">
                  {{fromData.TR + fromData.rt}}
                </span>

            <span class="td" v-show="list.ctnPrice && list.ctnPrice!=0.00">集装箱费总价：
                  <span v-show="list.ctnPrice &&list.ctnPrice!=0.00">   {{ fromData.nuit}}  {{((fromData.nuit=="￥"?list.ctnPrice:list.ctnPriceD)*list.cartonCount).toFixed(2)}} </span>
                  <span  :class="{'sold':list.oldCtnPrice}" v-show="list.oldCtnPrice &&list.oldCtnPriceR!=0.00 && list.oldCtnPriceR != list.ctnPriceD"> {{ fromData.nuit}}  {{((fromData.nuit=="￥"?list.oldCtnPriceR:list.oldCtnPrice)*list.cartonCount).toFixed(2)}}</span>
                </span>

            <span class="td" v-show="list.linePrice && list.linePrice!=0.00"> 运输费：
                  <span v-show="list.linePrice && list.linePrice!=0.00 ">{{ fromData.nuit}}  {{((fromData.nuit=="￥"?list.linePrice : list.linePriceD)*list.cartonCount).toFixed(2)}}
                  </span>
                  <span  :class="{'sold':list.oldLinePrice}" v-show="list.oldLinePrice && list.oldLinePrice != 0.00 && list.oldLinePriceR != list.linePrice"> {{ fromData.nuit}}  {{((fromData.nuit=="￥"?list.oldLinePriceR:list.oldLinePrice)*list.cartonCount).toFixed(2)}}</span>
            </span>
            <!--<span class="td"  v-show="list.consignPrice  && list.consignPrice!=0.00"> 拖车费：-->
                  <!--<span v-show="list.consignPrice && list.consignPrice!=0.00 ">{{ fromData.nuit}}  {{((fromData.nuit=="￥"?list.consignPrice:list.consignPriceD)*list.cartonCount).toFixed(2)}}</span>-->
                  <!--<span  :class="{'sold':list.oldConsignPrice }"  v-show="list.oldConsignPrice && list.oldConsignPrice!=0.00 && list.oldConsignPrice != list.consignPriceD"> {{fromData.nuit}}  {{((fromData.nuit=="￥"?list.oldConsignPriceR:list.oldConsignPrice) * list.cartonCount).toFixed(2)}}</span>-->

                <!--</span>-->
            <!--<span class="td" style="width: 30%;min-width:220px">小计：-->
            <!--<span v-show="list.cvalue" >-->
            <!--<span :class="{'sold':list.modifyCvalue && list.modifyCvalue!=0.00}">{{ fromData.nuit}} {{ fromData.nuit=="￥"?list.cvalue:list.cvalueD}}</span>-->
            <!--<span v-show="list.modifyCvalue && list.modifyCvalue!=0.00 ">{{ fromData.nuit}} {{ fromData.nuit=="￥"?list.modifyCvalue:list.modifyCvalueD}}</span>-->
            <!--</span>-->
            <!--</span>-->
            <span  class="add " v-show="user.admin == 1 && fromData.status <4" @click="updateFn(1,list)"> 修改</span>
          </p>
        </div>
        <p class="precTitle" > 增值费用<span class="smoli">(价格仅供参考)</span></p>
        <div class="cop" style="text-align: left;" >
          <p >
                <span class="index">
                      1
                </span>
            <span  class="precSpan">拖车费：{{ fromData.nuit}}  {{ fromData.nuit=="￥"?fromData.consignPrice:fromData.consignPriceD}}</span>
            <span class="sold" v-show="fromData.consignPrice && fromData.consignPriceD != fromData.oldconsignPrice" >{{ fromData.nuit}}  {{ fromData.nuit=="￥"?fromData.oldConsignPriceR:fromData.oldconsignPrice}}</span>
            <span  class="add"   v-show="user.admin ==1 && fromData.status < 4"> <span @click="updateFn(5)"  >修改 </span></span>
          </p>
          <p >
                <span class="index">
                      2
                </span>
            <span  class="precSpan">派送费：{{ fromData.nuit}}  {{ fromData.nuit=="￥"?fromData.sendPrice:fromData.sendPriceD}}</span>
            <span class="sold"  v-show="fromData.sendPrice &&  fromData.oldsendPrice!= fromData.sendPriceD">{{ fromData.nuit}}  {{ fromData.nuit=="￥"?fromData.oldsendPriceR:fromData.oldsendPrice}}</span>

            <span  class="add"   v-show="user.admin ==1 && fromData.status < 4"> <span @click="updateFn(6)"  >修改 </span></span>
          </p>
        </div>
        <p class="precTitle" > 额外费用<span class="smoli">(价格仅供参考)</span></p>
        <div class="cop" style="text-align: left;" >
          <p v-for="(list ,index ) in cost">
                <span class="index">
                      {{index +1}}
                </span>
            <span  class="precSpan">{{ list.costName}}  ： <span >{{ fromData.nuit}}  {{ fromData.nuit=="￥"?list.cost:list.costD}}</span>  <span :class="{'sold':list.cost != list.oldCost}"  v-show="list.cost != list.oldCost">{{ fromData.nuit}}  {{ fromData.nuit=="￥"?list.oldCost:list.oldCostD}}</span> </span>
            <span  class="add" v-show="user.admin ==1 && fromData.status < 4" > <span @click="updateFn(2,list)">修改 </span> / <span @click="updateFn(4,list)"> 删除</span> </span>
          </p>
          <p style="" v-show="user.admin ==1 && fromData.status < 4">
              <span @click="updateFn(3)" style="cursor: pointer;">
                <span class="el-icon-plus" style="border-radius: 10px;background-color: #0062a2;color: #fff;margin-right: 10px" ></span>新增费用
              </span>
          </p>
        </div>
        <div style="height: 30px"></div>
      </div>
    </div>
  </div>
</template>
<style scoped>
  .prec .cop .add{cursor: pointer;color: #999;float: right;margin-left: 0px }
  .prec .cop .index{border: 1px solid #000;display: block;width: 15px;height: 15px;line-height: 15px;text-align: center;border-radius: 85px;position: absolute;top: 8px;margin: 0px}

 .list .other p{font-size: 14px;color: #333}

  p{ text-align: left;font-size: 14px;color: #606266;}

  textarea{width: 100%;background: none;border: 0px none;height: 40px}

  .sev p{line-height: 30px }
  footer{width: 100%;clear: both }
  .set .container .main{float: left;width:80% }
  .set .container .show .main{margin-left: 80px}
  body{background-color:#f7f7f7}
  table{border-right:1px solid #909090;border-bottom:1px solid #909090;margin-left: 20px;width: 80%;margin-top: 40px}
  table  td{border-left:1px solid #909090;border-top:1px solid #909090;font-size: 12px;}
  .table table{border:0px none;}
  .table  table  td{border:0px none;text-align: left;line-height: 40px;}
  table td input{width: 100%;height: 40px;background: none;border: 0px none;text-indent: 10px}
  .table table td input{display:none}
  .table table td p{}
   table td p{display:none}

  .imgBoxs img{max-width: 126px;height: 90px}
  .list{box-sizing: border-box;padding: 15px 30px; position: relative}
  .list p{line-height:25px;font-size: 16px;text-align: left;padding: 5px 0px}
   span.td{margin-left: 25px}
  .list p .precSpan{margin-left: 25px}
  .list .addrss span{margin-right: 0px}
  .title{text-align: left;line-height: 50px;border-bottom: 1px solid #e1e1e1;}
  .textRight{width: 100%;margin-top: auto;}
  .textRight .right {width: 42%;}
  .textRight .right p{text-align:left ;font-size: 14px;font-weight: bold}
  .textRight .money p{text-align: right;font-size: 14px;font-weight: bold}
  .textRight .money {width: 58%;}
  .textRight .money .cuntNubmer{font-size: 18px;font-weight: bold;color:#fd8d00 }
  .textRight .money .cuntText{font-size: 18px;font-weight: bold;color:#fd8d00 }
  .list .precTitle{font-size: 20px;color: #0062a2;padding-top:30px;padding-left:10px;padding-bottom: 15px}
  .precTitle .smoli{ font-size: 12px;color: #999;margin-left: 10px}
  .prec .cop{width: 85%;margin-left:40px;line-height: 30px;border-bottom: 1px solid #e1e1e1;min-width: 600px}
  .prec .cop p{ width: 100%;font-size: 14px;color: #000;border-top: 1px solid #e1e1e1;position: relative}
  .prec .cop .td{display: block;float: left;width: 40%;min-width: 150px}
  .cuntBox{width: 30%;;min-height: 200px ;position: absolute;right: 0px;top:50%}
  .cuntCop{width: 80%;min-height: 200px;max-width: 260px}
  .cuntBox .cuntCop{position: absolute;top: -30%;right: 10%}
  .web .cuntBox .cuntCop{right: 15%}
  .dotted{border-bottom: 1px dotted #000;cursor: pointer}
  .sold{ text-decoration:line-through;color: #999;margin-left: 10px;font-size: 12px}
  .none{display: none}
  @media only screen and (min-width: 1200px){
    .set .container .main{float: left;width:80% }
    .prec .cop .td{display: block;float: left;width: 42%;min-width: 150px}
  }
  @media only screen and (min-width: 1366px){
    .set .container .main{float: left;width:83% }
    .cuntBox .cuntCop{right: 15%}

  }
  @media only screen and (min-width: 1600px){
    .set .container .main{float: left;width:85% }
    .cuntBox .cuntCop{right: 20%}
    .prec .cop .td{display: block;float: left;width: 40%;min-width: 150px}

  }
  @media only screen and (min-width: 1920px){
    .set .container .main{float: left;width:88% }
    .cuntBox .cuntCop{right: 25%}
    .prec .cop .td{display: block;float: left;width: 40%;min-width: 150px}
  }


</style>
<script>
  import {mapState, mapActions} from 'vuex'
  import Public from '@/vuex/public'
  export default {
    name: 'my-oderChart',
    created () {
      // 查看本页面路由 绑定对应页面class
      this.$store.commit('commitBizDetails', null)
      this.fromData.id = this.$route.query.id
      if(this.fromData.id){

      }else {
        this.fromData.bizType = 1
      }
      this.type = this.$route.query.type
      var usr = sessionStorage.getItem('user');
      if(usr) {
        usr = JSON.parse(usr);

        if(usr.type == 1){
          usr.type = 2
          // this.$router.push({ name: 'AdminConfig' })
        }
      }else {

        if(this.check != 'login'){
          // this.$router.push({ name: 'AdminConfig' })
        }
      }
      this.user = usr

    },
    data () {
      return {
        disabled:true,
        cost:[
          {
          costName:'拖车费用',cvalue:'678',cvalueD:"100"
        },//{
        //   costName:'报关',unit:'$',cost:'100'
        // },{
        //   costName:'人工',unit:'$',cost:'105'
        // },{
        //   costName:'包装',unit:'$',cost:'100'
        // }
        ],
        transitCost:[],
        costNameShow:false,
        disabled3:true,
        user:{
          type:2
        },
        width:'500px',
        width2:30,
        shows:false,
        type:null,
        fromTitle:'添加费用',
        addcost:{},
        fromData : {

        },
        from : {
          id:'',
          costName:'',// 费用名称
          orderId:'',// 订单id
          cost:'', // 杂费金额
          unit:2,//单位
          fromType:"",//表单类
          consignPrice:'',//拖车费用
          ctnPrice:'',//集装箱费用
          linePrice:'',//线路费用
        },
        ctnPrice:false,
        consignPrice:false,
        linePrice:false,
        originCost:'',

        title:'订单详情',
        money: [{
          value: 2,
          label: '美元'
        }, {
          value: 1,
          label: '人民币'
        }],
        options2: [{
          value: 1,
          label: '待确认',
          disable:false
        },{
          value: 2,
          label: '已确认',
          disable:false
        },{
          value: 3,
          label: '已提交委托书',
          disable:false
        },{
          value: 4,
          label: '已付款',
          disable:false
        },{
          value: 5,
          label: '在途运输',
          disable:false
        },{
          value: 6,
          label: '运输完成',
          disable:false
        },{
          value: 7,
          label: '已失效',
          disable:false,
          none:true,
        }],
        options3: [{
          value: '20GP',
          label: '20GP'
        }, {
          value: '40GP',
          label: '40GP'
        }, {
          value: '40HQ',
          label: '40HQ'
        }],
        rules:{
          cost: [  { required: true, message: '请选择箱型', trigger: 'blur'}],
          consignPrice: [  { required: true, message: '请选择箱型', trigger: 'blur'}],
          ctnPrice: [  { required: true, message: '请选择箱型', trigger: 'blur'}],
          linePrice: [  { required: true, message: '请选择箱型', trigger: 'blur'}],
        }
      }
    },
    methods: {
      ...mapActions({
        showQuotationDetails:'quotationDetails',
        addCost:'addCost',
        modifyQuotationOrderDetail:'modifyQuotationOrderDetail',
        deleteCost:'deleteCost',
        modifyQuotationOrderStatus:'modifyQuotationOrderStatus'
      }),
      login () {
        this.$router.push({ name: 'map' })
      },
      goBack(){
        this.$router.back(-1)
      },
      setFn(){

        this.$refs['from'].validate((valid) => {
          if (valid) {
            // 添加、修改，额外费用接口
            this.from.unit =  this.fromData.nuit == '$'? 2: this.fromData.nuit == '￥'?1:2

            if(this.from.fromType == 3 || this.from.fromType == 2){
              var parm = [{
                id:this.from.id,
                costName:this.from.costName,
                orderId:this.fromData.id,
                cost:parseFloat(this.from.cost),
                unit:parseInt(this.from.unit),
                originCost:parseFloat(this.originCost)
              }]

              this.addCost(parm)
            }else { // 修改基础费用
              var parm = {
                id :this.from.id,
                linePrice : parseFloat(this.from.linePrice),
                ctnPrice : parseFloat(this.from.ctnPrice),
                consignTotalPrice:this.from.fromType==5?parseFloat(this.from.cost) : '',
                sendTotalPrice: this.from.fromType==6?parseFloat(this.from.cost):'',
                orderId:this.fromData.id,
                unit:parseInt(this.from.unit),
                originLinePrice: parseFloat(this.from.originLinePrice) || '',
                originCtnPrice: parseFloat(this.from.originCtnPrice) || '',
                originConsignTotalPrice:this.from.fromType==5 ? parseFloat(this.originCost) : '',
                originSendTotalPrice: this.from.fromType==6 ? parseFloat(this.originCost) : ''
              }
              var linePrice = this.moneychange('',parm.linePrice,parm.unit,this.fromData.rate).D
              var ctnPrice = this.moneychange('',parm.ctnPrice,parm.unit,this.fromData.rate).D
              var consignPrice = this.moneychange('',parm.consignPrice,parm.unit,this.fromData.rate).D

              // 查看输入价格是否和
              if(parm.originLinePrice){
                if(linePrice == parm.originLinePrice){
                  delete parm.originLinePrice
                  delete parm.linePrice
                }
              }
              if(parm.originCtnPrice){
                if(ctnPrice == parm.originCtnPrice){
                  delete parm.originCtnPrice
                  delete parm.ctnPrice
                }
              }
              if(parm.originSendTotalPrice){
                if(consignPrice == parm.originSendTotalPrice){
                  delete parm.originSendTotalPrice
                  delete parm.sendTotalPrice
                }
              }
              if(parm.originConsignTotalPrice){
                if(consignPrice == parm.originConsignTotalPrice){
                  delete parm.originConsignTotalPrice
                  delete parm.consignTotalPrice
                }
              }

              this.modifyQuotationOrderDetail(parm)
            }
          } else {
            console.log('error submit!!');
            return false;
          }
        });

      },
      statusCheck(){

      },
      updateOderStatus(status){
        var parm = {
          orderId :this.fromData.id,
          status: this.fromData.status
        }
        this.modifyQuotationOrderStatus(parm)
      },
      //详情解析
      dataFn(res){
        res = res.body.data
        var time = Public.publicLo.timeCheng()
        if(res.createTime){
          time = Public.publicLo.timeCheng(res.createTime)
        }

        var dat= res.transitCost,linePrice={D:0,R:0},ctnPrice={D:0,R:0},consignPrice={D:0,R:0},sendPrice={D:0,R:0},cvalue={D:0,R:0},rate,transitCostTotal;
        this.transitCost=[];
        if(!res.cartonCount){
          res.cartonCount = 1
        }
        for(let i in dat){


           if(dat[i].volume){
             dat[i].cartonCount = dat[i].rt
           }else {
             dat[i].cartonCount = dat[i].cartonCount? dat[i].cartonCount :1
           }
          // 没有修改后价格，取原价 计算总价
          var datline = (dat[i].modifyLinePrice ? dat[i].modifyLinePrice : dat[i].linePrice),
            datctnPrice= dat[i].modifyCtnPrice ? dat[i].modifyCtnPrice : dat[i].ctnPrice,
            datconsignPrice= dat[i].modifyConsignPrice ? dat[i].modifyConsignPrice : dat[i].consignPrice;

          // 记录实际价格 单价
          var newlinePrice = this.moneychange('',datline,dat[i].unit,dat[i].rate),
            newctnPrice = this.moneychange('',datctnPrice,dat[i].unit,dat[i].rate),
            newconsignPrice = this.moneychange('',datconsignPrice,dat[i].unit,dat[i].rate);
            // 计算总价
          linePrice.D =  linePrice.D + (newlinePrice.D*dat[i].cartonCount)
          linePrice.R =  linePrice.R + (newlinePrice.R*dat[i].cartonCount)
          ctnPrice.D =  ctnPrice.D + (newctnPrice.D*dat[i].cartonCount)
          ctnPrice.R =  ctnPrice.R + (newctnPrice.R*dat[i].cartonCount)
          // consignPrice.D =  consignPrice.D + (newconsignPrice.D*dat[i].cartonCount)
          // consignPrice.R =  consignPrice.R + (newconsignPrice.R*adt[i].cartonCount)


          // 记录汇率
          rate = dat[0].rate
          // 记录原价
        var  oldlinePrice = this.moneychange('',dat[i].linePrice,dat[i].unit,dat[i].rate),
          oldctnPrice = this.moneychange('',dat[i].ctnPrice,dat[i].unit,dat[i].rate);




          this.transitCost.push({
            "id":dat[i].id,
            "volume":dat[i].volume,
            "weight":dat[i].weight,
            "cartonCount":dat[i].cartonCount ,
            "ctnOwner":dat[i].ctnOwner == 1? '中铁':dat[i].ctnOwner == 2?'租箱':dat[i].ctnOwner == 3?'买箱':dat[i].ctnOwner == 4?'俄铁':dat[i].ctnOwner == 5?'大洋':'',
            "cartonType":dat[i].cartonType,

            "linePrice":newlinePrice.R.toFixed(2),
            "ctnPrice":newctnPrice.R.toFixed(2),
            "consignPrice":newconsignPrice.R.toFixed(2),

            "linePriceD":newlinePrice.D.toFixed(2),
            "ctnPriceD":newctnPrice.D.toFixed(2),
            "consignPriceD":newconsignPrice.D.toFixed(2),
            "linePetty":dat[i].linePetty,
            "unit":dat[i].linePetty,
            "rate":dat[i].rate,
            "cvalue":this.moneychange('',dat[i].cvalue,dat[i].unit,dat[i].rate).R.toFixed(2),
            "cvalueD":this.moneychange('',dat[i].cvalue,dat[i].unit,dat[i].rate).D.toFixed(2),
            oldLinePrice:oldlinePrice.D ? oldlinePrice.D.toFixed(2) : '',
            oldCtnPrice:oldctnPrice.D ? oldctnPrice.D.toFixed(2)  : '',
          //  oldConsignPrice:oldconsignPrice.D ? oldconsignPrice.D.toFixed(2)  : '',
            oldLinePriceR:oldlinePrice.R ? oldlinePrice.R.toFixed(2) : '',
            oldCtnPriceR:oldctnPrice.R ? oldctnPrice.R.toFixed(2)  : '',
           // oldConsignPriceR:oldconsignPrice.R ? oldconsignPrice.R.toFixed(2)  : '',
            "remark":dat[i].remark,
            "createTime":dat[i].createTime,
            "updateTime":dat[i].updateTime
          })
        }
        dat= res.cost
        this.cost=[]

        for (let i in dat){
          var cost =this.moneychange('',dat[i].cost,dat[i].costUnit,rate)
          var modifyCost =this.moneychange('',dat[i].modifyCost,dat[i].costUnit,rate)
          this.cost.push({
             id:dat[i].id,
             costName:dat[i].costName,
            oldCost:cost.R.toFixed(2), // 原价
            oldCostD:cost.D.toFixed(2),//
            cost: modifyCost.R.toFixed(2),// 折扣后价格
            costD: modifyCost.D.toFixed(2)
          })
        }
        cvalue = this.moneychange('',res.cvalue,2,rate)
       // oldconsignPrice = this.moneychange('',dat[i].consignPrice,dat[i].unit,dat[i].rate);
        consignPrice = this.moneychange('',res.addcost.consignTotalPrice,res.unit,res.rate);
        sendPrice = this.moneychange('',res.addcost.sendTotalPrice,res.unit,res.rate);
      var   modifyConsignTotalPrice = this.moneychange('',res.addcost.modifyConsignTotalPrice,res.unit,res.rate),
          modifySendTotalPrice = this.moneychange('',res.addcost.modifySendTotalPrice,res.unit,res.rate);
        this.fromData = {
          "id":res.id,
          "number":res.number,// 订单号
          "customerName":res.customerName,// 公司名称
          "cttName":res.cttName,// 联系人
          "cttPhone":res.cttPhone,//联系人电话
          "bizType":res.bizType==1?'班列':res.bizType==2?'直发':res.bizType==3?'中转':res.bizType==4?'海铁联运':'异常',//运输类型
          "origin":res.origin|| '',//起始的
          "dest":res.dest || '',//目的地
          "status":res.status,
          goodsName:res.goodsName,
          "cartonType":res.cartonType,//箱型
          "cartonCount":res.cartonCount,//箱量
          "transitPort":Public.publicLo.getCityById(res.transitPort).cityCN || '',//过境
          "createTime":Public.publicLo.timeCheng(res.createTime).ymd || '', //下单时间
          linePrice:linePrice.R ? linePrice.R.toFixed(2) : '',
          ctnPrice:ctnPrice.R ? ctnPrice.R.toFixed(2) : '',
          consignPrice:modifyConsignTotalPrice.R.toFixed(2),
          cvalue:cvalue.R ? cvalue.R.toFixed(2) : 0,
          linePriceD:linePrice.D ? linePrice.D.toFixed(2) : '',
          ctnPriceD:ctnPrice.D ? ctnPrice.D.toFixed(2) : '',
          consignPriceD:modifyConsignTotalPrice.D.toFixed(2),
          cvalueD:cvalue.D ? cvalue.D.toFixed(2) : '',
          nuit:'$',
          unit:2,
          rate :rate,
          costTotal: this.moneychange('',res.costTotal,2,rate).R.toFixed(2),
          costTotalD: this.moneychange('',res.costTotal,2,rate).D.toFixed(2),
          consignAddress:res.consignAddress,
          sendAddress:res.sendAddress,
          sendPrice:modifySendTotalPrice.R.toFixed(2),
          sendPriceD:modifySendTotalPrice.D.toFixed(2),
          oldconsignPrice:consignPrice.D.toFixed(2),
          oldsendPrice:sendPrice.D.toFixed(2),
          oldconsignPriceR:consignPrice.R.toFixed(2),
          oldsendPriceR:sendPrice.R.toFixed(2),

        }
        if(this.fromData)
        if(this.transitCost[0].volume){
          this.fromData.volume = this.transitCost[0].volume
          this.fromData.weight = this.transitCost[0].weight
          this.fromData.TR =  this.fromData.weight/500 > this.transitCost[0].volume ? this.fromData.weight+'(kg)/500 ： TR = ' : this.transitCost[0].volume + '(m³) ： RT = ' ;
          this.fromData.rt = this.transitCost[0].cartonCount
        }
      },
      // 价格转换
      moneychange(arr,number,a,reta){
        var c = reta
        var res = arr ||{
          'R':0,
          'D':0
        }

        if(!number){
          return res
        }else {
          // number = parseFloat(number)
        }
        if(a==1){
          res.R = res.R + number;
          res.D = res.D+(number/c)
        }
        if(a!=1){
          res.D = res.D + number;
          res.R = res.R+(number*c)
        }
        res.reta = reta

        return res
      },
      // 操作是否成功
      listStatus (res) {

        if (res.status == 0) {
          // 修改成功
          var text = '';
          if(res.code == 'addCost'){
            if(this.from.id){
              text = '额外费用修改成功'
            }
            if(!this.from.id){
              text = '额外费用添加成功'
            }
          }
          if(res.code == 'modifyQuotationOrderDetail'){
            text = '费用修改成功'
          }
          if(res.code == 'addQuotation'){
            text = '费用添加成功'
          }
          if(res.code == 'deleteCost'){
            text = '额外费用删除成功'
          }
          if(res.code == 'modifyQuotationOrderStatus'){
            text = '订单状态修改成功'
          }
          this.shows = false;

          this.openSuccess(text);
          // if(!this.fromData.id){
          //   this.fromData.id = res.data.id
          // }else {
          //
          // }
          this.from={
            id:'',
            costName:'',
            orderId:'',
            cost:'',
            unit:2,
            fromType:""
          }
          // 刷新列表
          var parm = {
            id: this.fromData.id
          }
          this.showQuotationDetails(parm);
        }
        if (res.status != 0) {
          // 修改 修改失败
          var text = '添加失败';
          this.openError(text)
        }
        // 清空 vuex 中的本次记录，以免被下次操作状态造成混淆
        this.$store.commit('updateStatusTo', {body: null})
      },

      openSuccess (text) {
        this.$message({
          message: text,
          type: 'success'
        })
      },

      openError (text) {
        this.$message.error(text)
      },

      // 校验

      keyUp(parm,status){
        parm = parm.replace(/[^0-9-]+/,'');
        if(status == 'cttPhone'){
          this.fromData.cttPhone = parm
        }
        if(status == 'weight'){
          this.fromData.weight = parm
        }
        if(status == 'volume'){
          this.fromData.volume = parm
        }
        if(status == 'cvalue'){
          this.fromData.cvalue = parm
        }
      },

      updateFn(a,list){
        //删除
        if(a == 4){
          var parm ={
            id :list.id,
            orderId:this.fromData.id,
            originCost:list.costD
          }
          this.deleteCost(parm)
          return
        }
        this.shows = true;
        this.from.fromType = a;
        if(a == 1){ // 修改当前费用
          var consignPrice,ctnPrice,linePrice //拖车费用 集装箱费用 线路费用
          if( this.from.unit == 1){
            linePrice = (list.linePrice && list.linePrice != 0.00) ? list.linePrice : 0
            ctnPrice = (list.ctnPrice && list.ctnPrice != 0.00) ? list.ctnPrice : ''
            consignPrice = (list.consignPrice && list.consignPrice != 0.00) ? list.consignPrice : ''
          }else {
            linePrice =(list.linePriceD && list.linePriceD != 0.00) ? list.linePriceD : ''
            ctnPrice =(list.ctnPriceD && list.ctnPriceD != 0.00) ?  list.ctnPriceD : ''
            consignPrice =(list.consignPriceD && list.consignPriceD != 0.00) ?  list.consignPriceD : ''
          }

          this.costNameShow = false
          this.from.id = list.id;
          // 表单 线路 集装箱 拖车
          this.from.linePrice =  linePrice
          this.from.ctnPrice =  ctnPrice
          this.from.consignPrice = consignPrice;
          // 原价 线路 集装箱 拖车  ！ 0.00 赋值 0

          this.from.originLinePrice = linePrice
          this.from.originCtnPrice = ctnPrice
          //this.from.originConsignPrice = (list.oldConsignPrice && list.oldConsignPrice!=0.00)?list.oldConsignPrice:''
          this.fromTitle = '修改当前费用'
          if(this.from.linePrice){
            this.linePrice = true
          }
          if(this.from.ctnPrice){
            this.ctnPrice = true
          }
          if(this.from.consignPrice){
            this.consignPrice = true
          }

        }
        if(a == 2){
          this.costNameShow = true
          this.from.id = list.id;
          this.from.costName = list.costName;
          this.from.cost = this.from.unit == 1 ? list.cost : list.costD
          this.originCost = list.costD+''

          this.fromTitle = '修改额外费用'
        }
        if(a == 3){
          this.costNameShow = true
          this.originCost = ''
          this.fromTitle = '添加额外费用'
        }
        if(a == 5){
         // 修改拖车
          this.costNameShow = true
          this.from.costName = '拖车费';
          this.from.cost = this.from.unit == 1 ? this.fromData.consignPrice : this.fromData.consignPriceD
          this.originCost = this.fromData.consignPriceD
          this.fromTitle = '修改拖车费用'
        }
        if(a == 6){
          //修改派送
          this.costNameShow = true
          this.from.costName = '派送费';
          this.from.cost = this.from.unit == 1 ? this.fromData.sendPrice : this.fromData.sendPriceD
          this.originCost = this.fromData.sendPriceD
          this.fromTitle = '修改派送费用'
        }
      }
      },
    computed: {
      DetailData() {
        var parm = this.Detail
        if (parm) {

          this.dataFn(parm)
        }
        return 1
      },
      updateStatusData: function () {
        var parm = this.updateStatus

        if (parm) {
          if(parm== 'out'|| parm=='outErorr'){

          }else {
            this.listStatus(parm)
          }
        }
        return 1
      },
      us: function () {
        var parm = this.userData

        if (parm) {
          this.user = parm.data

        }
        return 1
      },
      ...mapState([
        'Detail',
        'updateStatus',
        'language',
        'userData'
      ])
    },
    mounted () {

    },
    components: {

    }
  }
</script>

